#include <iostream>
#include <sstream>
using namespace std;

#include <purewell/system.hpp>
#include <purewell/code/escape.hpp>
using namespace purewell;

int
main(int argc, char* argv[])
{
	gPWSystem.setLibraryLogStream(&cerr);

	string src("Hello, world! O'relly\nGood day~");

	cout << "Source: <<";
	cout.write(src.c_str(), src.size()+1);
	cout << ">>" << endl << endl;

	char ebuf[src.size()*2+1];
	size_t ebuflen(gPWEscape.encode(ebuf, src.c_str(), src.size()+1));
	ebuf[ebuflen+1] = 0x00;

	cout << "Encode: <<";
	cout.write(ebuf, ebuflen);
	cout << ">>" << endl << endl;

	char dbuf[ebuflen+1];
	size_t dbuflen(gPWEscape.decode(dbuf, ebuf, ebuflen));
	dbuf[dbuflen+1] = 0x00;

	cout << "Decode: <<";
	cout.write(dbuf, dbuflen);
	cout << ">>" << endl << endl;

	istringstream is(src);
	cout << "Encode: <<";
	gPWEscape.encode(cout, is);
	cout << ">>" << endl << endl;

	string ebuf2(ebuf, ebuflen);
	istringstream is2(ebuf2);
	cout << "Decode: <<";
	gPWEscape.decode(cout, is2);
	cout << ">>" << endl << endl;
}

